Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JavaTM 2 Platform Std. Ed. v1.4.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.awt.dnd
Class DragSource

    java.lang.Object
      |
      +--java.awt.dnd.DragSource

All Implemented Interfaces:
  Serializable

public class DragSource
extends Object
implements Serializable

The `DragSource` is the entity responsible for the initiation of the Drag and Drop operation, and may be used in a number of scenarios:

- 1 default instance per JVM for the lifetime of that JVM.
- 1 instance per class of potential Drag Initiator object (e.g TextField). [implementation dependent]
- 1 per instance of a particular `Component`, or application specific object associated with a `Component` instance in the GUI. [implementation dependent]
- Some other arbitrary association. [implementation dependent]

Once the `DragSource` is obtained, a `DragGestureRecognizer` should also be obtained to associate the `DragSource` with a particular `Component`.

The initial interpretation of the user's gesture, and the subsequent starting of the drag operation are the responsibility of the implementing `Component`, which is usually implemented by a `DragGestureRecognizer`.

When a drag gesture occurs, the `DragSource`'s startDrag() method shall be invoked in order to cause processing of the user's navigational gestures and delivery of Drag and Drop protocol notifications. A `DragSource` shall only permit a single Drag and Drop operation to be current at any one time, and shall reject any further startDrag() requests by throwing an `IllegalDnDOperationException` until such time as the extant operation is complete.

The startDrag() method invokes the createDragSourceContext() method to instantiate an appropriate `DragSourceContext` and associate the `DragSourceContextPeer` with that.

If the Drag and Drop System is unable to initiate a drag operation for some reason, the startDrag() method throws a `java.awt.dnd.InvalidDnDOperationException` to signal such a condition. Typically this exception is thrown when the underlying platform system is either not in a state to initiate a drag, or the parameters specified are invalid.

Note that during the drag, the set of operations exposed by the source at the start of the drag operation may not change until the operation is complete. The operation(s) are constant for the duration of the operation with respect to the `DragSource`.

Since:
  1.2
See Also:
  Serialized Form

Field Summary
`static Cursor` | `DefaultCopyDrop` The default `Cursor` to use with a copy operation indicating that a drop is currently allowed.
`static Cursor` | `DefaultCopyNoDrop` The default `Cursor` to use with a copy operation indicating that a drop is currently not allowed.
`static Cursor` | `DefaultLinkDrop` The default `Cursor` to use with a link operation indicating that a drop is currently allowed.
`static Cursor` | `DefaultLinkNoDrop` The default `Cursor` to use with a link operation indicating that a drop is currently not allowed.
`static Cursor` | `DefaultMoveDrop` The default `Cursor` to use with a move operation indicating that a drop is currently allowed.
`static Cursor` | `DefaultMoveNoDrop` The default `Cursor` to use with a move operation indicating that a drop is currently not allowed.

Constructor Summary
`DragSource()` Construct a new `DragSource`.

Method Summary
`void` | `addDragSourceListener(DragSourceListener dsl)` Add the specified `DragSourceListener` to this `DragSource` to receive drag source events during drag operations intiated with this `DragSource`.
`void` | `addDragSourceMotionListener(DragSourceMotionListener dsml)` Add the specified `DragSourceMotionListener` to this `DragSource` to receive drag motion events during drag operations intiated with this `DragSource`.
`DragGestureRecognizer` | `createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl)` Creates a new `DragSourceRecognizer` that implements the default abstract subclass of `DragGestureRecognizer` for this `DragSource`, and sets the specified `Component` and `DragGestureListener` on the newly created object.
`DragGestureRecognizer` | `createDragGestureRecognizer(Class recognizerAbstractClass, Component c, int actions, DragGestureListener dgl)` Creates a new `DragGestureRecognizer` that implements the specified abstract subclass of `DragGestureRecognizer`, and sets the specified `Component` and `DragGestureListener` on the newly created object.
`protected DragSourceContext` | `createDragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)` Create the `DragSourceContext` to handle this drag.
`static DragSource` | `getDefaultDragSource()` This method returns the `DragSource` object associated with the underlying platform.
`DragSourceListener[]` | `getDragSourceListeners()` Returns an array of all the `DragSourceListener`s registered with this `DragSource`.
`DragSourceMotionListener[]` | `getDragSourceMotionListeners()` Returns an array of all the `DragSourceMotionListener`s registered with this `DragSource`.
`FlavorMap` | `getFlavorMap()` This method returns the `FlavorMap` for this `DragSource`.
`EventListener[]` | `getListeners(Class listenerType)` Returns an array of all the objects currently registered as `FooListener`s upon this `DragSource`.
`static boolean` | `isDragImageSupported()` This method returns a `boolean` indicating whether or not drag `Image` support is available on the underlying platform.
`void` | `removeDragSourceListener(DragSourceListener dsl)` Remove the specified `DragSourceListener` from this `DragSource`.
`void` | `removeDragSourceMotionListener(DragSourceMotionListener dsml)` Remove the specified `DragSourceMotionListener` from this `DragSource`.
`void` | `startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point dragOffset, Transferable transferable, DragSourceListener dsl)` Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Image` to drag, the offset of the `Image` origin from the hotspot of the `Cursor` at the instant of the trigger, the subject data of the drag, and the `DragSourceListener`.
`void` | `startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap)` Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Image` to drag, the offset of the `Image` origin from the hotspot of the `Cursor` at the instant of the trigger, the `Transferable` subject data of the drag, the `DragSourceListener`, and the `FlavorMap`.
`void` | `startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl)` Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Transferable` subject data of the drag, and the `DragSourceListener`.
`void` | `startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap)` Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Transferable` subject data of the drag, the `DragSourceListener`, and the `FlavorMap`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DefaultCopyDrop

    public static final Cursor DefaultCopyDrop

  The default `Cursor` to use with a copy operation indicating that a drop is currently allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

### DefaultMoveDrop

    public static final Cursor DefaultMoveDrop

  The default `Cursor` to use with a move operation indicating that a drop is currently allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

### DefaultLinkDrop

    public static final Cursor DefaultLinkDrop

  The default `Cursor` to use with a link operation indicating that a drop is currently allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

### DefaultCopyNoDrop

    public static final Cursor DefaultCopyNoDrop

  The default `Cursor` to use with a copy operation indicating that a drop is currently not allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

### DefaultMoveNoDrop

    public static final Cursor DefaultMoveNoDrop

  The default `Cursor` to use with a move operation indicating that a drop is currently not allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

### DefaultLinkNoDrop

    public static final Cursor DefaultLinkNoDrop

  The default `Cursor` to use with a link operation indicating that a drop is currently not allowed. `null` if `GraphicsEnvironment.isHeadless()` returns `true`.

  See Also:
    `GraphicsEnvironment.isHeadless()`

Constructor Detail

### DragSource

    public DragSource()
               throws HeadlessException

  Construct a new `DragSource`.

Throws:
  `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
See Also:
  `GraphicsEnvironment.isHeadless()`

Method Detail

### getDefaultDragSource

    public static DragSource getDefaultDragSource()

  This method returns the `DragSource` object associated with the underlying platform.

  Returns:
    the platform DragSource
  Throws:
    `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`

### isDragImageSupported

    public static boolean isDragImageSupported()

  This method returns a `boolean` indicating whether or not drag `Image` support is available on the underlying platform.

  Returns:
    if the Drag Image support is available on this platform

### startDrag

    public void startDrag(DragGestureEvent trigger,
                          Cursor dragCursor,
                          Image dragImage,
                          Point imageOffset,
                          Transferable transferable,
                          DragSourceListener dsl,
                          FlavorMap flavorMap)
                   throws InvalidDnDOperationException

  Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Image` to drag, the offset of the `Image` origin from the hotspot of the `Cursor` at the instant of the trigger, the `Transferable` subject data of the drag, the `DragSourceListener`, and the `FlavorMap`.

  Parameters:
    `trigger` - The `DragGestureEvent` that initiated the drag
    `dragCursor` - The initial `Cursor` or `null` for defaults
    `dragImage` - The image to drag or null,
    `imageOffset` - The offset of the `Image` origin from the hotspot of the `Cursor` at the instant of the trigger
    `transferable` - The subject data of the drag
    `dsl` - The `DragSourceListener`
    `flavorMap` - The `FlavorMap` to use, or `null`

  Throws:
    ``java.awt.dnd.InvalidDnDOperationException`` - if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.
    `InvalidDnDOperationException`

### startDrag

    public void startDrag(DragGestureEvent trigger,
                          Cursor dragCursor,
                          Transferable transferable,
                          DragSourceListener dsl,
                          FlavorMap flavorMap)
                   throws InvalidDnDOperationException

  Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Transferable` subject data of the drag, the `DragSourceListener`, and the `FlavorMap`.

  Parameters:
    `trigger` - The `DragGestureEvent` that initiated the drag
    `dragCursor` - The initial `Cursor` or `null` for defaults
    `transferable` - The subject data of the drag
    `dsl` - The `DragSourceListener`
    `flavorMap` - The `FlavorMap to use or `null`

    `
  Throws:
    ``java.awt.dnd.InvalidDnDOperationException`` - if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.
    `InvalidDnDOperationException`

### startDrag

    public void startDrag(DragGestureEvent trigger,
                          Cursor dragCursor,
                          Image dragImage,
                          Point dragOffset,
                          Transferable transferable,
                          DragSourceListener dsl)
                   throws InvalidDnDOperationException

  Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Image` to drag, the offset of the `Image` origin from the hotspot of the `Cursor` at the instant of the trigger, the subject data of the drag, and the `DragSourceListener`.

  Parameters:
    `trigger` - The `DragGestureEvent` that initiated the drag
    `dragCursor` - The initial `Cursor` or `null` for defaults
    `dragImage` - The `Image` to drag or `null`
    `transferable` - The subject data of the drag
    `dsl` - The `DragSourceListener`

  Throws:
    ``java.awt.dnd.InvalidDnDOperationException`` - if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.
    `InvalidDnDOperationException`

### startDrag

    public void startDrag(DragGestureEvent trigger,
                          Cursor dragCursor,
                          Transferable transferable,
                          DragSourceListener dsl)
                   throws InvalidDnDOperationException

  Start a drag, given the `DragGestureEvent` that initiated the drag, the initial `Cursor` to use, the `Transferable` subject data of the drag, and the `DragSourceListener`.

  Parameters:
    `trigger` - The `DragGestureEvent` that initiated the drag
    `dragCursor` - The initial `Cursor` or `null` for defaults
    `transferable` - The subject data of the drag
    `dsl` - The `DragSourceListener`

  Throws:
    ``java.awt.dnd.InvalidDnDOperationException`` - if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.
    `InvalidDnDOperationException`

### createDragSourceContext

    protected DragSourceContext createDragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp,
                                                        DragGestureEvent dgl,
                                                        Cursor dragCursor,
                                                        Image dragImage,
                                                        Point imageOffset,
                                                        Transferable t,
                                                        DragSourceListener dsl)

  Create the `DragSourceContext` to handle this drag. To incorporate a new `DragSourceContext` subclass, subclass `DragSource` and override this method.

  Parameters:
    `dscp` - The `DragSourceContextPeer` for this drag
    `dragCursor` - The initial `Cursor` to display
    `dragImage` - The `Image` to drag or `null`
    `imageOffset` - The offset of the `Image` origin from the hotspot of the cursor at the instant of the trigger
    `dsl` - The `DragSourceListener`

  Returns:
    the `DragSourceContext`

### getFlavorMap

    public FlavorMap getFlavorMap()

  This method returns the `FlavorMap` for this `DragSource`.

  Returns:
    the `FlavorMap` for this `DragSource`

### createDragGestureRecognizer

    public DragGestureRecognizer createDragGestureRecognizer(Class recognizerAbstractClass,
                                                             Component c,
                                                             int actions,
                                                             DragGestureListener dgl)

  Creates a new `DragGestureRecognizer` that implements the specified abstract subclass of `DragGestureRecognizer`, and sets the specified `Component` and `DragGestureListener` on the newly created object.

  Parameters:
    `recognizerAbstractClass` - The requested abstract type
    `actions` - The permitted source drag actions
    `c` - The `Component` target
    `dgl` - The `DragGestureListener` to notify

  Returns:
    the new `DragGestureRecognizer` or `null` if the Toolkit.createDragGestureRecognizer() method has no implementation available for the requested `DragGestureRecognizer` subclass and returns `null`.

### createDefaultDragGestureRecognizer

    public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c,
                                                                    int actions,
                                                                    DragGestureListener dgl)

  Creates a new `DragSourceRecognizer` that implements the default abstract subclass of `DragGestureRecognizer` for this `DragSource`, and sets the specified `Component` and `DragGestureListener` on the newly created object. For this `DragSource` the default is `MouseDragGestureRecognizer`.

  Parameters:
    `c` - The `Component` target for the recognizer
    `actions` - The permitted source actions
    `dgl` - The `DragGestureListener` to notify

  Returns:
    the new `DragGestureRecognizer` or `null` if the Toolkit.createDragGestureRecognizer() method has no implementation available for the requested `DragGestureRecognizer` subclass and returns `null`.

### addDragSourceListener

    public void addDragSourceListener(DragSourceListener dsl)

  Add the specified `DragSourceListener` to this `DragSource` to receive drag source events during drag operations intiated with this `DragSource`. If a `null` listener is specified, no action is taken and no exception is thrown.

  Parameters:
    `dsl` - the `DragSourceListener` to add.
  Since:
    1.4
See Also:
  `removeDragSourceListener(java.awt.dnd.DragSourceListener)`, `getDragSourceListeners()`

### removeDragSourceListener

    public void removeDragSourceListener(DragSourceListener dsl)

  Remove the specified `DragSourceListener` from this `DragSource`. If a `null` listener is specified, no action is taken and no exception is thrown. If the listener specified by the argument was not previously added to this `DragSource`, no action is taken and no exception is thrown.

  Parameters:
    `dsl` - the `DragSourceListener` to remove.
  Since:
    1.4
See Also:
  `addDragSourceListener(java.awt.dnd.DragSourceListener)`, `getDragSourceListeners()`

### getDragSourceListeners

    public DragSourceListener[] getDragSourceListeners()

  Returns an array of all the `DragSourceListener`s registered with this `DragSource`.

  Returns:
    all of this `DragSource`'s `DragSourceListener`s or an empty array if no such listeners are currently registered
  Since:
    1.4
See Also:
  `addDragSourceListener(java.awt.dnd.DragSourceListener)`, `removeDragSourceListener(java.awt.dnd.DragSourceListener)`

### addDragSourceMotionListener

    public void addDragSourceMotionListener(DragSourceMotionListener dsml)

  Add the specified `DragSourceMotionListener` to this `DragSource` to receive drag motion events during drag operations intiated with this `DragSource`. If a `null` listener is specified, no action is taken and no exception is thrown.

  Since:
    1.4
See Also:
  `removeDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener)`, `getDragSourceMotionListeners()`

### removeDragSourceMotionListener

    public void removeDragSourceMotionListener(DragSourceMotionListener dsml)

  Remove the specified `DragSourceMotionListener` from this `DragSource`. If a `null` listener is specified, no action is taken and no exception is thrown. If the listener specified by the argument was not previously added to this `DragSource`, no action is taken and no exception is thrown.

  Parameters:
    `dsml` - the `DragSourceMotionListener` to remove.
  Since:
    1.4
See Also:
  `addDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener)`, `getDragSourceMotionListeners()`

### getDragSourceMotionListeners

    public DragSourceMotionListener[] getDragSourceMotionListeners()

  Returns an array of all the `DragSourceMotionListener`s registered with this `DragSource`.

  Returns:
    all of this `DragSource`'s `DragSourceMotionListener`s or an empty array if no such listeners are currently registered
  Since:
    1.4
See Also:
  `addDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener)`, `removeDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener)`

### getListeners

    public EventListener[] getListeners(Class listenerType)

  Returns an array of all the objects currently registered as `FooListener`s upon this `DragSource`. `FooListener`s are registered using the `addFooListener` method.

  Parameters:
    `listenerType` - the type of listeners requested; this parameter should specify an interface that descends from `java.util.EventListener`
  Returns:
    an array of all objects registered as `FooListener`s on this `DragSource`, or an empty array if no such listeners have been added
  Throws:
    ``ClassCastException`` - if `listenerType` doesn't specify a class or interface that implements `java.util.EventListener`
  Since:
    1.4
See Also:
  `getDragSourceListeners()`, `getDragSourceMotionListeners()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JavaTM 2 Platform Std. Ed. v1.4.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.